<?php
namespace app\mobile\controller;

use app\common\controller\Base;
use think\Db;
use app\index\model\ChongZhi;
use app\index\model\TiXian;
use app\index\model\Username;
use app\common\model\StateChange;
class Member extends Base
{
	public function _initialize(){
		header("Content-type:text/html;charset=utf-8");
		parent::_initialize();
		//用户中心所需参数
		$start = array(
				'user_all'                     =>$this->user_all,
				'logo'                          =>$this->logo,
				'app_down'                =>$this->app_down,
				'now_time_windows' => $this->now_time_windows,
				'usnameclass'            => $this->usnameclass
		);
		$this->state = new StateChange();
		$this->assign('s',$this->user_all);
		$this->assign($start);
		$this->assign('cur','member');
	}
	public function index(){

		if(!$this->user_all['username']) {
		    $this->redirect('mobile/Member/notlogin');
		}
		$user = $this->user_all['username'];
		//查账号
		$find = Db::name('username')->alias('a')->join('__US_CLASS__ us','a.us_class=us.id','left')->where('username',$user)->find();
		$xxcount = Db::name('xiaoxi')->where('username',$this->user_all['username'])->order('id','DESC')->limit(50)->select();
		$open = Db::name('agent_off')->where('id',1)->value('open');
		$this->assign('open',$open);
		$count = 0;
		foreach ($xxcount as $va){
			if($va['ifdq']==0){
				$count += 1;
			}
		}
		/**
		 * @todo 等级分析
		 */
		$level = Db::name("us_class")->field("id,class_name,czl,xml")->order("czl asc")->select();
		$current_level = $find['us_class'];
		$next_level = "";
		$next_money = 0;
		$next_xml = 0;
		foreach($level as $k=>$v){
			if( $current_level==$v['id'] && isset($level[$k+1]) ){
				$next_level = $level[$k+1]['class_name'];
				$next_money = ceil( floatval($level[$k+1]['czl'])-floatval($find['czzje']) );
				$next_xml = ceil( floatval($level[$k+1]['xml'])-floatval($find['tzzje']) );
				break;
			}
		}

		$this->assign('next_level',$next_level);
		$this->assign('next_money',$next_money);
		$this->assign('next_xml',$next_xml);
		$title = '会员中心';
		$this->assign('count',$count);
		$this->assign('f',$find);
		$this->assign('user',$user);
		$this->assign('header',$this->user_all['img']);
		$this->assign('title',$title);

		if($find['swzh']) {
		    return $this->fetch('sw_index');
		} else {
		    return $this->fetch();
		}
	}
	
	public function notlogin() {
	    $title = '会员中心';
	    $this->assign('title',$title);
	    return $this->fetch();
	}
	
	/**
	 * 充值列表
	 */
	public function chongzhi() {
		$this->assign('title','充值中心');
		$list = Db::name("pay_method")->where(['status'=>1])->order("seq asc")->select();
		$this->assign('list',$list);
		return $this->fetch("recharge_method");

	    if(!$this->user_all['username']) {
	        js_tishi('请先登录账号！','/mobile/user/login');exit;
	    }
	    $info = Db::name('pay_xianshang')->field('id,pay_name,open,level')->select();
	    foreach($info as &$v) {
	        $v['level_open'] = 0;
	        $level_arr = explode(',',$v['level']);
	        if(in_array($this->user_all['us_class'],$level_arr)) $v['level_open'] = 1;
	    }

	    $this->assign('title','充值中心');
	    $this->assign('info',$info);
	    return $this->fetch();
	}
	
	/**
	 * 线下充值
	 * @param string $je
	 * @param string $liuyan
	 * @param string $zffs
	 * @return Ambigous <\think\mixed, string>
	 */
	public function xxchongzhi($je='',$appDateTime='',$liuyan='',$zffs=''){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		//区分线下支付方式，默认为银行
		$pay_type = input('get.pay_type') ? input('get.pay_type') : 'bank';
	    if(!in_array($pay_type,['wx','ali','bank'])) $pay_type = 'bank';
	        
		$je = sprintf("%.2f",$je);
		$user = $this->user_all['username'];
		$sw = Db::name('xt_shiwan')->where('id',1)->find();
		$sure = strpos($user, $sw['qianzhui']);
		$query = Db::name('username')->where('username',$user)->find();
		$usclass = input('usclass')?input('usclass'):'';
		$hyzsbs = input('hy_zsbs')?input('hy_zsbs'):'';
		$xsczje = input('xsczje')?input('xsczje'):'';
		$xsczzsbs = input('xsczzsbs')?input('xsczzsbs'):'';
		$xxczje = input('xxczje')?input('xxczje'):'';
		$xxczzsbs = input('xxczzsbs')?input('xxczzsbs'):'';
		$account_id = input('account') ? input('account') : 0;
		
		//线下账户列表
		$xxlist = Db::name('pay_xxlist')->select();
		foreach($xxlist as $v) {
		    $xxlist_data[$v['xx_remark']][] = $v;
		}
		
		//会员等级与百分比
		$ts = Db::name('us_class')->where('id',$query['us_class'])->find();
		
		//判断单次充值是否满一定金额，达到赠送金额；
		$xtcz = StateChange::name('xt_chongzhi')->where('id',1)->find();
		if($sure !== 0){
			
			//开始处理充值
			if($this->user_all['swzh'] == 1) {
				js_tishi('试玩账号无法充值！','/mobile/member/index');exit;
			}
			
			//充值提交
			if($query['nbzh']>0){
				if($je !=''){
					$state = new StateChange();
					$where = array('username'=>$user,'nbzh'=>1);
					$savedata = array('je'=>$query['je']+$je,'czzje'=>$query['czzje']+$je);
					$state->SaveRecharge('username', $where, $savedata);
					return js_tishi('操作成功', '/mobile/member/index');
				}
			}else{
				//判断防骚扰
				$count_sheuid = Db::name('xt_czfsr')->find();
				if($count_sheuid['open'] > 0) {
					$nowys = time() - $count_sheuid['time_xx'] * 60;
					$old_czjl = Db::name('chongzhi_list')->where('username',$this->user_all['username'])->where('cztime','>',$nowys)->find();
					if($old_czjl['id'] > 0) {
						js_tishi("系统充值防骚扰已开启，{$count_sheuid['time_xx']}分钟内只能充值1次！",'/mobile/member/index');
						exit;
					}
				}
				//提交充值
				if($je != '' && $liuyan !='' && $appDateTime !=''){
					$time = strtotime($appDateTime);
					$ddbh = 'S_'.$time.rand(0,999);
					if(!$account_id) {
					    js_tishi('请选择充值账户！','/mobile/member/chongzhi');exit;
					}
					
					if($zffs==1) {
					    $xxbank='微信转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					} elseif($zffs==2) {
					    $xxbank='支付宝转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					}elseif($zffs==4) {
						$xxbank='QQ转账';
						$account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
						$czclass=2;
						$czadmin='';
					} else {
					    $xxbank='网银转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					}
					$msje=0;$msbs=0;
					if($czclass==1){
						if($je>=$xsczje){
							$msje = $je*$xsczzsbs/100;
							$msbs = $xsczzsbs;
						}
					}elseif($czclass==2){
						if($je>=$xxczje){
							$msje = $je*$xxczzsbs/100;
							$msbs = $xxczzsbs;
						}
					}
					$zsbs = $hyzsbs;
					$zsje = $je*$hyzsbs/100;
					$chongzhi = new ChongZhi();
					
					if($je>=10){
						if($chongzhi->WeiXinRecharge($czadmin,$ddbh,$je,$user,'0','0',$czclass,$xxbank,$time,get_ip(),'0',$liuyan,$zsje,$zsbs,$msje,$msbs,$usclass,$account,'0.00',$this->user_all['je'])){
							js_tishi('提交成功', '/mobile/Member/index');
						}
					}else{
						js_tishi('输入正确的金额', '/mobile/Member/xxchongzhi?pay_type='.$pay_type);
					}
				}
			}
			//页面显示
			$title = '充值中心';
			$this->assign('time',time());
			$this->assign('xtcz',$xtcz);
			$this->assign('ts',$ts);
			$this->assign('title',$title);
			$this->assign('xxlist',$xxlist_data);
			
			if($pay_type == 'wx') {
			    $weixin = Db::name('pay_xxlist')->where('xx_weixin',1)->order('id','ASC')->find();
			    $this->assign('weixin',$weixin);
			    return $this->fetch('chongzhi_wx');
			}
			if($pay_type == 'ali') {
			    $zhifubao = Db::name('pay_xxlist')->where('xx_zhifubao',1)->order('id','ASC')->find();
				$this->assign('zhifubao',$zhifubao);
			    return $this->fetch('chongzhi_ali');
			}
			if($pay_type == 'bank') {
			    $wangyin = Db::name('pay_xxlist')->where('xx_wangyin',1)->order('id','ASC')->find();
			    $this->assign('wangyin',$wangyin);
			    return $this->fetch('chongzhi_bank');
			}
		}else{
			js_tishi('试玩账号无法充值！','/mobile/Member/index');
		}
	}
	/**
	 * 高通线上充值
	 */
	public function gtPay() {
	    $id = input('get.id') ? input('get.id') : 0;
	    
	    if(!$this->user_all['username']) {
	        js_tishi('请先登录账号！','/mobile/user/login');exit;
	    }
	    if($this->user_all['swzh'] != 0) {
	       js_tishi('试玩账号无法充值！','/mobile/Member/index');exit;
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
	        js_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi');exit;
	    }

	    $username = $this->user_all['username'];
	    $pay_type = Db::name('pay_type_list')->where(['method'=>1,'mob'=>1])->order('order','DESC')->column('type_name','type_value');

        //页面显示
        $title = '高通支付';
        $this->assign('title',$title);
        $this->assign('username',$username);
        $this->assign('pay_type',$pay_type);
        return $this->fetch('gt_pay');
	}
	
	/**
	 * 速付线上充值
	 */
	public function sfPay() {
	    $id = input('get.id') ? input('get.id') : 0;
	    
	    if(!$this->user_all['username']) {
	        js_tishi('请先登录账号！','/mobile/user/login');exit;
	    }
	    if($this->user_all['swzh'] != 0) {
	        js_tishi('试玩账号无法充值！','/mobile/Member/index');
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
	        js_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi');exit;
	    }
	    
	    $username = $this->user_all['username'];
	    $pay_type = Db::name('pay_type_list')->where(['method'=>2,'mob'=>1])->order('order','DESC')->column('type_name','type_value');
	     
	    //页面显示
	    $title = '速付支付';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('pay_type',$pay_type);
	    return $this->fetch('sf_pay');
	}
	
	/**
	 * 支付宝扫码充值
	 */
	public function aliCode() {
	    $id = input('get.id') ? input('get.id') : 0;
	    
	    if(!$this->user_all['username']) {
	        js_tishi('请先登录账号！','/mobile/user/login');exit;
	    }
	    if($this->user_all['swzh'] != 0) {
	        js_tishi('试玩账号无法充值！','/mobile/Member/index');
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
	        js_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi');exit;
	    }
	
	    $username = $this->user_all['username'];
	    //线上二维码账户列表
	     $online_ac = Db::name('code_account')->where(['type'=>'alipay','lock'=>0])->select();
	
	    //页面显示
	    $title = '支付宝扫码';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('online_ac',$online_ac);
	    return $this->fetch('ali_code');
	}
	
	/**
	 * 微信扫码充值
	 */
	public function wxCode() {
	    $id = input('get.id') ? input('get.id') : 0;
	    
	    if(!$this->user_all['username']) {
	        js_tishi('请先登录账号！','/mobile/user/login');exit;
	    }
	    if($this->user_all['swzh'] != 0) {
	        js_tishi('试玩账号无法充值！','/mobile/Member/index');
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
	        js_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi');exit;
	    }

	    $username = $this->user_all['username'];
	    //线上二维码账户列表
	    $online_ac = Db::name('code_account')->where(['type'=>'wechat','lock'=>0])->select();

	    //页面显示
	    $title = '微信扫码';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('online_ac',$online_ac);
	    return $this->fetch('wx_code');
	}
	
	/**
	 * 提现页面
	 * @return Ambigous <\think\mixed, string>
	 */
	public function tixian(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$user = $this->user_all['username'];
		$r = Db::name('xt_shiwan')->where('id',1)->value('qianzhui');
		$sure = strpos($user, $r);
		if($sure !== 0){
			$t = Db::name('username')
					->alias('a')
					->join('__BANK__ b','b.id=a.bankname')
					->field('a.*,b.bankname as bank')
					->where('a.username',$user)->find();
			if($t['dml']>0){
                alert_back("打码量还剩".$t['dml']."，无法提现.");
			}else{
				
				$s = Db::name('xt_tixian')->where('id',1)->find();
				if($s['open'] < 1) {
					alert_back('提现功能尚未开启！');exit;
				}
				$now_times = date('Y-m-d')." 00:00:00";
				$now_times = strtotime($now_times);
				$count = Db::name('tixian_list')->where('username',$this->user_all['username'])->where('txtime','>',$now_times)->count();
				if($s['txcount'] > 0) {
					if($count >= $s['txcount']) {
                        alert_back('今日提现次数已用完！');exit;
					}
				}
				//判断是否绑定银行卡
				if($t['bankren'] && $t['bankno'] && $t['bank']){$t_ok='display:block;';$t_no='display:none;';}else{$t_ok='display:none;';$t_no='display:block;';}
				$bank = Db::name('bank')->select();
				$s['test'] = str_replace("\n","<br>",html_entity_decode($s['test']));
				$title = '在线提款';
				$this->assign('t',$t);
				$this->assign('s',$s);
				$this->assign('t_ok',$t_ok);
				$this->assign('t_no',$t_no);
				$this->assign('bank',$bank);
				$this->assign('title',$title);
				return $this->fetch();
			}
		}else{
			alert_back('试玩账号无法提现！');}
	}
	/**
	 * 添加银行卡并且设置付款密码
	 * @param string $ejmm
	 * @param string $bankren
	 * @param string $banksf
	 * @param string $bankno
	 * @param string $bankname
	 * @param string $banksq
	 * @param string $mobile
	 * @param string $qq
	 */
	public function tixianzl($ejmm='',$bankren='',$banksf='',$bankno='',$bankname='',$banksq='',$bank_zhihang='',$mobile='',$qq=''){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$user = $this->user_all['username'];
		if($ejmm!=''&&$bankren!=''&&$banksf!=''&&$bankno!=''&&$bankname!=''&&$banksq!=''&& $bank_zhihang!='' &&$mobile!=''&&$qq!='')
		{
			$count = Db::name("username")->where(['bankno'=>$bankno])->count();
			if( $count > 0 ){
				alert_back('您已注册有蚂蚁赢彩账户，请咨询客服帮助找回！');exit;
			}
			$res = Db::name('username')->where('username',$this->user_all['username'])->find();
			$tixian = new TiXian();
			$tixian->setTixianWithdraw($user, $ejmm, $bankren, $banksf, $bankno, $bankname, $banksq, $mobile, $qq,$bank_zhihang);
			$t = Db::name('xt_caijin')->where('id',1)->find();
			if($t['open'] == 0) {
				$je = $t['je'];
				$dml = $t['cj_dml'];
			} else {
				$je = 0;
				$dml = 0;
			}
			$jes = $je+$res['je'];
			$dml = $dml+$res['dml'];
			$zcj = $res['zcjje']+$je;
			if($je>0){
				$data = array('je'=>$jes,'zcjje'=>$zcj,'dml'=>$dml,'reg_je'=>$je,'bk_time'=>time());
				Db::name('username')->where('username',$this->user_all['username'])->update($data);
				Db::name('bank_caijin')->insert(array('username'=>$this->user_all['username'],'bankje'=>$je,'yue'=>$res['je'],'time'=>time(),'hqfs'=>$t['open']));
				$this->state->UserFaSong($this->user_all['username'], "您已绑定银行卡，赠送彩金：".$je."元.已到账，请注意查收！");

				$datas = array(
						'username'=>$this->user_all['username'],
						'user_class'=>$res['us_class'],
						'cjje'=>$je,
						'fstime'=>time(),
						'beizhu' => '系统赠送，用户绑定银行卡，赠送彩金',
						'czadmin' => '绑卡赠送彩金',
						'cjhje'=>$jes,
				);
				Db::name('caijin_list')->insert($datas);

			}
			js_tishi('绑定银行卡成功', '/mobile/Member/tixian');
		}else{

            alert_back('不能为空！');exit;
		}
	}
	/**
	 * 提取现金
	 * @param string $txje
	 * @param string $password
	 */
	public function tixianje(){
	    //开启事务
	    Db::startTrans();
	    if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		if(input('post.')){

			if($this->user_all['nbzh'] == 1) {
				js_tishi('内部账号不能提现！','/mobile/Member/tixian');exit;
			}
			//验证打码量是否满足要求
			$code_amount = Db::name('xt_dmsz')->find();
			if($code_amount['tx_yzdml'] == 1  && $this->user_all['dml'] > 0 ) {
				js_tishi("打码量未通过，您还需消费{$this->user_all['dml']}元才能提现！",'/mobile/Member/tixian');exit;
			}

			//提现设定处理
			$txje=input('post.txje');
			if( !is_numeric($txje)){
				js_tishi('输入正确金额', '/mobile/Member/tixian');
			}
			$draw_set = Db::name('xt_tixian')->find();
			if($draw_set['open'] < 1) {
				js_tishi("提现功能尚未开启！",'/mobile/Member/tixian');exit;
			}elseif( $draw_set['zxje'] > $txje || $draw_set['zdje'] < $txje ){
				js_tishi("提现金额不能小于{$draw_set['zxje']}，且不能大于{$draw_set['zdje']}",'/mobile/Member/tixian');exit;
			}

			//提现次数判断
			$now_times = date('Y-m-d')." 00:00:00";
			$now_times = strtotime($now_times);
			$count = Db::name('tixian_list')->where('username',$this->user_all['username'])->where('txtime','>',$now_times)->count();
			if($draw_set['txcount'] > 0 && $count >= $draw_set['txcount'] ) {
				js_tishi("今日提现次数已用完！",'/mobile/Member/tixian');exit;
			}
			//判断账号是否为冻结或者提现功能是否关闭或者为试玩账号
			if($this->user_all['open']==1 || $this->user_all['swzh']==1 || $this->user_all['tixian_open']==1) {
				js_tishi("您的账号目前为禁止提现状态！",'/mobile/Member/tixian');exit;
			}
			if( $txje > $this->user_all['je']) {
				js_tishi('可提现余额为'.$this->user_all['je'].',余额不足','/mobile/Member/tixian');exit;
			}

			$password = input('post.password');
			if($this->user_all['ejmm']==md5($password)){
				$je = $this->user_all['je']-$txje;
				try {
					$tixian = new TiXian();
					$tixian->setTixianJe($this->user_all['username'], $txje, '0', '0', time(), get_ip(), '0',$je);
					$tixian->setTixianSaveJe($this->user_all['username'], $je);
					Db::commit();
					js_tishi('已提交提现审核，请耐心等待', '/mobile/Member/index');
					exit;
				} catch (\Exception $e) {
					// 回滚事务
					Db::rollback();
					js_tishi('提现失败请重试', '/mobile/Member/index');
					exit;
				}
			}else{
				js_tishi('取款密码错误', '/mobile/Member/tixian');
			}
		}
	}
	/**
	 * 更改密码
	 */
	public function passxg(){
		$user = $this->user_all['username'];
		$r = Db::name('xt_shiwan')->where('id',1)->value('qianzhui');
		$sure = strpos($user, $r);
		if($sure !== 0){
			$title = '修改密码';
			$this->assign('title',$title);
			return $this->fetch();
		}else 
			js_tishi('试玩账号无法提现！','/mobile/Member/index');
	}
	/**
	 * 更改密码和提款密码
	 * @param string $old_password
	 * @param string $new_password
	 * @param string $new_password2
	 * @param string $passwordclass
	 */
	public function passxgmm(){
		//  if(!$this->user_all['username']) {
		//	js_tishi('请先登录账号！','/mobile/user/login');exit;
		//}
		$old_password = input('old_password');
		$new_password = input('new_password');
		$new_password2 = input('new_password2');
		$passwordclass = input('passwordclass');

        //验证
        $old_password = trim($old_password);
        $new_password = trim($new_password);
        $new_password2 = trim($new_password2);

        if(strlen($old_password)<6) {$this->error('请输入正确的密码');}
        if(strlen($new_password)<6) {$this->error('密码长度不够');}


        if($new_password==$new_password2){
            if($passwordclass == 1){
                $password = 'password';
                $password_model = 'updatePass';
            }else if($passwordclass == 2){
                $password = 'ejmm';
                $password_model = 'updatePassEjmm';
            }
            $user = $this->user_all['username'];

            $user_find = Db::name('username')->where('username',$user)->field($password)->find();
            if(md5($old_password) == $user_find[$password]){
                $ps = new Username();
                $ps->$password_model($user, md5($new_password));
                $this->success('修改成功');
            }else{
                $this->error('旧密码不一致');
            }

        }else{
            $this->error('两次密码不一样');

        }



	}
	/**
	 * 手机版投注记录
	 * @return Ambigous <\think\mixed, string>
	 */
	public function touzhu()
	{
		if(!$this->user_all['username']) {
            js_tishi('请先登录账号！','/mobile/user/login');exit;
        }
        //接收所需参数
        $tzid = input('tzid') ? input('tzid') : '';
        $czid = input('czid') ? input('czid') : '';
        $classtz = input('classtz') ? input('classtz') : '0';
        $timebh = input('timebh') ? input('timebh') : '1';
        $page = input('page') ? input('page') : 1;
        if($page < 1) $page = 1;
        $page_num = 10;
        //标记当前导航栏
        $this->assign('current','call');
        /* ------------------------------------------------投注记录详情----------------------------------------------- */
        //根据条件查询
        if($tzid  && $czid ) {
            if($this->user_all['nbzh'] == 1 || $this->user_all['swzh'] == 1) {
                 $yxsql_mysq="touzhu_list_sw";
             } else {
                 $yxsql_mysq="touzhu_list_ok";
             }
             //正常的订单
             $dingdan = Db::name('touzhu_list_no')->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();
             
             $dingdanzt = '待开奖';
             
             if(!$dingdan) {
                 $dingdan = Db::name($yxsql_mysq)->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();
             }

             //追号的订单
             if(!$dingdan) {
                 $dingdan = Db::name('touzhu_list_zh')->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();
            	 
                 $dingdanzt = '追号，待开奖';	 
             }
             $cnzmshdui = Db::name('caipai_list')->where('id',$czid)->find();
             if($cnzmshdui['cp_name_new'] == '') $cnzmshdui['cp_name_new'] = $cnzmshdui['cp_name_old'];
             //投注规格
             if($dingdan['nbzh'] == 1) $tzmss = '元';
             if($dingdan['nbzh'] == 2) $tzmss = '角';
             if($dingdan['nbzh'] == 3) $tzmss = '分';
             //判断是否开奖
             if($dingdan['kjjg'] < 1){
             	$kjjg = '未开奖';
             }else{
             	$kjjg = kjjg_split($dingdan['kjjg'], $dingdan['czid']);
             
             	if($dingdan['zjje']>0.001){
             	
             		$dingdanzt = '已中奖';
             	
             	}else{
             		$dingdanzt = '未中奖';
             	}
             }
             
             //获取开奖时间
             $dingdan['tz_time'] = date('Y-m-d H:i:s',$dingdan['tz_time']);
             //投注玩法
             if($dingdan['wfid'] > 0) {
                 $wfnames = Db::name('play_classify')->where('id',$dingdan['wfid'])->find();
             }
             if(!$wfnames['class_name_mini']) $wfnames['class_name_mini'] = $dingdan['tzhm'];
             if(!empty($wfnames['digit'])){
                 $dingdan['tzhm'] = digit($dingdan['tzhm'],$wfnames['digit'],$czid,$wfnames['id']);
             }
             
             $title= '投注记录';
             $this->assign('title',$title);
             $this->assign('kjjg',$kjjg);
             $this->assign('cnzmshdui',$cnzmshdui);
             $this->assign('dingdan',$dingdan);
             $this->assign('wfnames',$wfnames);
             $this->assign('tzmss',$tzmss);
             $this->assign('dingdanzt',$dingdanzt);
             return $this->fetch('touzhuxx');
         }
		 
         /* ------------------------------------------------投注记录列表----------------------------------------------- */
         
		 $all_cz_list = Db::name('caipai_list')->where('cp_if_open','<',2)->select();
		 $touzhu_all = $this->touzhuJilu($this->user_all['username'],$timebh,$czid,$classtz);
		 if(count($touzhu_all) > 0) {
		     $touzhu_all = multi_array_sort($touzhu_all,'tz_time');
		 }
		 
		 $zcount = count($touzhu_all);
		 $zys = ceil($zcount / $page_num);
		 if($page > $zys) $page = $zys;
		 $openjl = ($page - 1) * $page_num;
		 $touzhu_all = array_slice($touzhu_all,$openjl,$page_num);
		 
		 $czids = '';
		 $wfids = '';
         foreach($touzhu_all as &$xh_1) {
		    $czids .= $xh_1['czid'].',';
		    $wfids .= $xh_1['wfid'].',';
			$xh_1['tz_time'] = date('Y-m-d H:i:s',$xh_1['tz_time']);
         }

		$title= '投注记录';
		$this->assign('title',$title);
         $this->assign('tzid',$tzid);
         $this->assign('czid',$czid);
         $this->assign('classtz',$classtz);
         $this->assign('timebh',$timebh);
         $this->assign('zongcount',$zcount);
         $this->assign('zys',$zys);
         $this->assign('page',$page);
         $this->assign('list_ca',$all_cz_list);
		 $this->assign('touzhulist',$touzhu_all);
         return $this->fetch('touzhu');
	}
	/**
	 * 手机版用户提现记录
	 * @return Ambigous <\think\mixed, string>
	 */
	public function tixianjilv()
	{
		if(!$this->user_all['username']) {
            js_tishi('请先登录账号！','/mobile/user/login');exit;
        }
        $page = input('page') ? input('page') : 1;
        $page_num = 10;
        //查询提现记录
        $tixianjl = $this->tixianjl($this->user_all['username']);
        //总页数
        $zcount = count($tixianjl);
        $zys = ceil($zcount / $page_num);
        //页数限制
        if($page > $zys) $page = $zys;
        if($page < 1) $page = 1;
        $offset = ($page - 1) * $page_num;
        //处理提现记录
        if(count($tixianjl) > 0) {
            $tixianjl = multi_array_sort($tixianjl,'txtime');
        }
        $tixianjl = array_slice($tixianjl,$offset,$page_num);
        foreach($tixianjl as &$xh_1) {
            if($xh_1['zt'] == '1') $xh_1['zt'] = '成功';
            if($xh_1['zt'] == '0') $xh_1['zt'] = '处理中';
            $xh_1['txtime'] = date('m-d H:i:s',$xh_1['txtime']);
        }
        $title= '提现记录';
        $this->assign('title',$title);
        $this->assign('current','drawMoney');
        $this->assign('zys',$zys);
        $this->assign('zcount',$zcount);
        $this->assign('page',$page);
        $this->assign('touzhulist',$tixianjl);
        return $this->fetch('tixianjl');
	}
	/**
	 * 手机版充值记录
	 * @return Ambigous <\think\mixed, string>
	 */
	public function payjl()
	{
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$page = input('page') ? input('page') : 1;
		$page_num = 10;
		//总页数
		$zcount = Db::name('chongzhi_list')->where('username',$this->user_all['username'])->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询充值记录
		$offset = ($page - 1) * $page_num;
		$where = [
			'username' => $this->user_all['username'],
			'zt' => ['neq',9]
		];
		$payjls = Db::name('chongzhi_list')->where($where)->order('id','DESC')->limit($offset,$page_num)->select();
		foreach($payjls as &$py) {
			$py['cztime'] = date('m-d H:i:s',$py['cztime']);
			if($py['czclass']==1) $py['czclass'] = $py['xxbank'];//线上
			if($py['czclass']==2) $py['czclass'] = $py['xxbank'].'(线下充值)';//线下
			if($py['czclass']==3) $py['czclass'] = '手工充值';
			if($py['zt'] == 1) {
				$py['zt'] = '已到账';
			}elseif($py['zt']== '-1') {
				$py['zt'] = '充值失败';
			}else{
				$py['zt'] = '处理中';
			}
		}
		unset($py);
		$title= '充值记录';
		$this->assign('title',$title);
		$this->assign('current','recharge');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	}
	/**
	 * 手机版系统发放彩金
	 */
	public function caijin()
	{
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$page = input('page') ? input('page') : 1;
		$page_num = 10;
		//查询总页数
		$zcount = Db::name('caijin_list')->where('username',$this->user_all['username'])->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询彩金记录
		$offset = ($page - 1) * $page_num;
		$payjls = Db::name('caijin_list')->where('username',$this->user_all['username'])->order('id','DESC')->limit($offset,$page_num)->select();
		foreach($payjls as &$v) {
			$v['fstime'] = date('m-d H:i:s',$v['fstime']);
		}
		$title= '系统彩金';
		$this->assign('title',$title);
		$this->assign('current','bounty');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	}
	
	public function xiaoxi(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		//消息列表
		$data=array('ifdq'=>1);
		$xx_listdb = Db::name('xiaoxi')->where('username',$this->user_all['username'])->order('id','DESC')->limit(50)->select();
		foreach($xx_listdb as &$v) {
			Db::name('xiaoxi')->where('id',$v['id'])->update($data);
		    $v['xx_time'] = date('Y-m-d H:i:s',$v['xx_time']);
		}

		$title= '消息中心';
		$this->assign('title',$title);
		$this->assign('current','message');
		$this->assign('xiaoxi_ls',$xx_listdb);
		return $this->fetch();
	}
/**
 * 代理
 */	
	public function daili(){
		$title= '代理';
		$this->assign('title',$title);
		return $this->fetch();
	}
	public function dailiCenter(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		return $this->fetch('dailizhongxin');
	}
	
	public function dailishuoming(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		return $this->fetch();
	}
	
	public function dailibaobiao(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$user = input('user')?input('user'):'';
		$start=0;
		$end=time();
		
		if(input('day')=='' || input('day')=='今天'){
			$start = strtotime(date('Y-m-d').' 00:00:00');
			$end = strtotime(date('Y-m-d').' 23:59:59');
		
		}
		if(input('day')=='昨天'){
			$start = strtotime(date("Y-m-d",strtotime("-1 day")).' 00:00:00');
			$end = strtotime(date("Y-m-d",strtotime("-1 day")).' 23:59:59');
		
		}
		if(input('day')=='本周'){
			$start = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)).' 00:00:00');
			$end = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)).' 23:59:59');
		
		}
		if(input('day')=='本月'){
			$start = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')).' 23:59:59');
		
		}
		if(input('day')=='上月'){
			$start = strtotime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400).' 23:59:59');
		
		}
		$time = [$start,$end];
		$u = Db::name('username')->where('tjr',$this->user_all['username'])->column('username');
		if($user != '' && in_array($user, $u)!==false){
			$count = $this->dlXiaJiZongRenShu($user,$time);
			$counts = Db::name('username')->where('tjr',$user)->count();
			$yj = Db::name('agent_balance')->where('agent', $user)->whereTime('add_time', 'BETWEEN', $time)->value('SUM(balance)');
		}else{
			$count = $this->dlXiaJiZongRenShu($this->user_all['username'],$time);
			$counts = Db::name('username')->where('tjr',$this->user_all['username'])->count();
			$yj = Db::name('agent_balance')->where('agent', $this->user_all['username'])->whereTime('add_time', 'BETWEEN', $time)->value('SUM(balance)');
			
		}
		$yj = Db::name('agent_balance')->where('agent',$this->user_all['username'])->whereTime('add_time','BETWEEN',$time)->value('SUM(balance)');
		$this->assign('yj',sprintf('%.2f',$yj));
		$this->assign('count',$count);
		$this->assign('counts',$counts);
		$this->assign('user',$user);
		$this->assign('time',time());
		$this->assign('day',input('day'));
		return $this->fetch();
	}
	
	public function LowerlevelReport(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$username = input('user');
		if($username){
			$user = Db::name('username')->where(['tjr'=>$username])->select();
		}else{
			$user = Db::name('username')->where(['tjr'=>$this->user_all['username']])->select();
		}
		foreach ($user as &$v){
			$yj = Db::name('agent_balance')->where('agent',$v['username'])->value('SUM(balance)');
			$v['sy'] = sprintf('%.2f',$yj);
		}
		$this->assign('user',$user);
		return $this->fetch('xiajibaobiao');
	}
	function dlXiaJiZongRenShu($user,$time){
		static $count = 0;
		static $tzje = 0;
		static $zjje = 0;
		static $hdlj = 0;
		static $tzrs = 0;
		static $txje = 0;
		static $czje = 0;
		static $czrs = 0;
		static $tdye = 0;
		$dl = Db::name('username')->where('username',$user)->value('fandian');
		$us = Db::name('username')->field('username,dl,xjrens')->where('tjr',$user)->select();
		foreach ($us as $val){
			$tdye += Db::name('username')->where('username',$val['username'])->whereTime('reg_time','BETWEEN',$time)->value('SUM(je)');
			$je = Db::name('touzhu_list_ok')->where('username',$val['username'])->whereTime('tz_time','BETWEEN',$time)->value('SUM(tzje)');
			$tzje += $je;
			$cz = Db::name('chongzhi_list')->where(['username'=>$val['username'],'zt'=>1,'czadmin'=>['<>','']])->whereTime('cztime','BETWEEN',$time)->value('SUM(je)');
			$czje += $cz;
			$txje += Db::name('tixian_list')->where(['username'=>$val['username'],'zt'=>1,'shadmin'=>['<>',''],'czadmin'=>['<>','']])->whereTime('txtime','BETWEEN',$time)->value('SUM(txje)');
			$zjje += Db::name('touzhu_list_ok')->where('username',$val['username'])->whereTime('tz_time','BETWEEN',$time)->value('SUM(zjje)');
			$hdlj += Db::name('caijin_list')->where('username',$val['username'])->whereTime('fstime','BETWEEN',$time)->value('SUM(cjje)');
			if($je){$tzrs += 1;}
			if($cz){$czrs += 1;}
			if($val['dl']==1){
				$this->dlXiaJiZongRenShu($val['username'],$time);
			}
		}

		return array('fandian'=>$dl,'tdye'=>$tdye,'czje'=>$czje,'czrs'=>$czrs,'count'=>$count,'tzje'=>$tzje,'zjje'=>$zjje,'cjje'=>$hdlj,'tzrs'=>$tzrs,'txje'=>$txje);
	}
	
	public function xiajiguanli(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$username = input('user');
		if($username){
			$user = Db::name('username')->where(['tjr'=>$username])->select();
		}else{
			$user = Db::name('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($user as &$v){
			$v['rs'] = $this->dlXiaJiZongRenShu($v['username'], [0,time()]);
		}

		$this->assign('user',$user);
		return $this->fetch();
	}
	
	public function touzhumingxi(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$start=0;
		$end=time();
		$user = '';
		if(input('user')){
			$user = input('user');
		}
		$day = input('day','today');
		$touzhu = array();
		$us = '';
		if($user!=''){
			$tzmx = Db::name('username')->field('username')->where('username',$user)->select();
		}else{
			$tzmx = Db::name('username')->field('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($tzmx as $v){
			$us .=$v['username'].',';
		}
		$touzhu['dkj'] = Db::name('touzhu_list_no')->where('username','IN',$us)->whereTime('tz_time',$day)->select();
		$touzhu['wzj'] = Db::name('touzhu_list_ok')->where('username','IN',$us)->whereTime('tz_time',$day)->where('zjje','0')->select();
		$touzhu['yzj'] = Db::name('touzhu_list_ok')->where('username','IN',$us)->whereTime('tz_time',$day)->where('zjje','>','0')->select();
		$this->assign('time',input('time','今天'));
		$this->assign('touzhu',$touzhu);
		$this->assign('user',$user);
		return $this->fetch();
	}
	
	public function jiaoyimingxi(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$start=0;
		$end=time();
		$user = '';
		if(input('user')){
			$user = input('user');
		}
		if(input('day')=='' || input('day')=='今天'){
			$start = strtotime(date('Y-m-d').' 00:00:00');
			$end = strtotime(date('Y-m-d').' 23:59:59');
		
		}
		if(input('day')=='昨天'){
			$start = strtotime(date("Y-m-d",strtotime("-1 day")).' 00:00:00');
			$end = strtotime(date("Y-m-d",strtotime("-1 day")).' 23:59:59');
		
		}
		if(input('day')=='本周'){
			$start = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)).' 00:00:00');
			$end = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)).' 23:59:59');
		
		}
		if(input('day')=='本月'){
			$start = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')).' 23:59:59');
		
		}
		if(input('day')=='上月'){
			$start = strtotime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400).' 23:59:59');
		
		}
		$time = [$start,$end];
		
		$jiaoyi = array();
		$us = '';
		if($user!=''){
			$tzmx = Db::name('username')->field('username')->where('username',$user)->select();
		}else{
			$tzmx = Db::name('username')->field('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($tzmx as $v){
			$us .=$v['username'].',';
		}
		$jiaoyi['chongzhi'] = Db::name('chongzhi_list')->where('username','IN',$us)->whereTime('cztime','BETWEEN',$time)->select();
		$jiaoyi['tixian'] = Db::name('tixian_list')->where('username','IN',$us)->whereTime('txtime','BETWEEN',$time)->select();
		$this->assign('day',input('day'));
		$this->assign('jiaoyi',$jiaoyi);
		$this->assign('user',$user);
		return $this->fetch();
	}
	
	public function xiajikaihu(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		if(input('number') && input('number')>0){
			$fandian = input('number');
			if($fandian<=0){alert_back('返点不能小于0');}
			$yqm = $this->code();
			$u = Db::name('username')->where('username',$this->user_all['username'])->field('tjm,fandian')->find();
			$date = array('tjm'=>$u['tjm'].'|'.$yqm.'-'.$fandian);
			if(Db::name('username')->where('username',$this->user_all['username'])->update($date)){
				js_tishi('生成成功', 'xiajikaihu');
			}else{
				alert_back('生成失败');
			}
			
		}else{
			$user = Db::name('username')->where('username',$this->user_all['username'])->find();
			$tjm = explode('|',$user['tjm']);
			$tjm_new = array();
			$tjm_old = $tjm[0];
			unset($tjm[0]);
			foreach ($tjm as $key=>$v){
				$tjm_new[$key]=explode('-', $v);
			}
			$ymxz = Db::name('dl_domain')->where('status',1)->select();
			$this->assign('tjmold',$tjm_old);
			$this->assign('ymxz',$ymxz);
			$this->assign('tjm',$tjm_new);
			$this->assign('user',$user);
			return $this->fetch();
		}
	}
	public function yaoqingmaDelete(){
		$key = input('key');
		$username = $this->user_all['username'];
		$user = Db::name('username')->where('username',$username)->field('id,tjm')->find();
		$yaoqingma = explode('|',$user['tjm']);
		foreach($yaoqingma as $k=>$v){
			$yzm = explode('-',$v);
			if( isset($yzm[0]) && $yzm[0]==$key ) unset($yaoqingma[$k]);
		}
		$yaoqingma_new = implode('|',$yaoqingma);
		if(Db::name('username')->where('username',$username)->update(array('tjm'=>$yaoqingma_new))){
			return 1;
		}else{
			return 2;
		}		
	}
	
	public function shenqing(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$user = Db::name('username')->where('username',$this->user_all['username'])->value('dlshstatus');
		$this->assign('user',$user);
		return $this->fetch();
	}
	public function shenqinganniu(){
		$data['dlshstatus']=1;
		if(Db::name('username')->where('username',$this->user_all['username'])->update($data)){
			js_tishi('已提交审核', 'index');
		}else{
			js_tishi('已提交过审核，请耐心等待', 'index');
		}
	}
	function code(){
		$code=rand('000000', '999999');
		
		/* for($i=1;$i<=2;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=1;$i++){
			$code .= chr(rand(65,90));
		}
		for($i=1;$i<=1;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=4;$i++){
			$code .= chr(rand(65,90));
		}
		for($i=1;$i<=2;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=3;$i++){
			$code .= chr(rand(65,90));
		} */
		if($code != ''){
			$yzm = Db::name('username')->field('tjm')->select();
			$tjm = '';
			foreach ($yzm as $v){$tjm .= $v['tjm'].'--';}
			if(strstr($tjm, $code)!==false){
				$this->code();
			}
		}
		return $code;
	}
	public function qita(){
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$title= '系统彩金';
		$page = input('page') ? input('page') : 1;
		$page_num = 12;
		//查询总页数
		$zcount = Db::name('caijin_list')->where('username',$this->user_all['username'])->where('cjje','>','0')->count();
		$zcount += Db::name('fs_list')->where('username',$this->user_all['username'])->where('fsje','>','0')->count();
		$zcount +=  Db::name('day_agent')->where('agent',$this->user_all['username'])->where('balance','>','0')->count();
		$zcount +=  Db::name('bonus_user')->where('username',$this->user_all['username'])->where('je','>','0')->count();
		$zcount +=  Db::name('username')->where('username',$this->user_all['username'])->where('reg_je','>','0')->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询彩金记录
		$offset = ($page - 1) * $page_num;
		$cj = Db::name('caijin_list')->field('cjje as je,beizhu as way,fstime as time')->where('username',$this->user_all['username'])->where('cjje','>','0')->order('fstime','DESC')->limit($offset,$page_num)->select();
		$fs = Db::name('fs_list')->field('fsje as je,"返水" as way,distribute_time as time')->where('username',$this->user_all['username'])->where('fsje','>','0')->order('distribute_time','DESC')->limit($offset,$page_num)->select();
		$agent = Db::name('day_agent')->field('balance as je,"返佣" as way,add_time as time')->where('agent',$this->user_all['username'])->where('balance','>','0')->order('add_time','DESC')->limit($offset,$page_num)->select();
		$bonus = Db::name('bonus_user')->field('je,"红包" as way,time')->where('username',$this->user_all['username'])->where('je','>','0')->order('time','DESC')->limit($offset,$page_num)->select();
		$bk = Db::name('username')->field('reg_je as je,"绑卡彩金" as way,bk_time as time')->where('username',$this->user_all['username'])->where('reg_je','>','0')->select();
		
		$payjls = array_merge($bk,$cj,$fs,$agent,$bonus);
		if(isset($payjls[0])){
			$payjls = arraySequence($payjls,'time');
		}
		
		$this->assign('title',$title);
		$this->assign('current','bounty');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	}
	
	public function notice(){
		
		$title= '通知公告';
		$this->assign('title',$title);
		
		return $this->fetch();
	}
	
	public function zhmx(){

		$name = $this->user_all['username'];
		if(!$name) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		//0:今天,1:昨天,2:本周,3:本月,4:上月
		$date = input('date',0);
		$page = input('page',1);
		$limit = 20;
		$total = 0;
		switch( intval($date) ){
			case 1:
				$begin = strtotime( date("Y-m-d 00:00:00",strtotime("-1 day")) );
				$end = strtotime( date("Y-m-d 23:59:59",strtotime("-1 day")) );
				break;
			case 2:
				$begin = mktime( 0, 0 , 0, date("m"), date("d")-date("w")+1, date("Y") );
				$end = mktime( 23,59,59,date("m"), date("d")-date("w")+7, date("Y") );
				break;
			case 3:
				$begin = mktime(0, 0 , 0,date("m"),1,date("Y"));
				$end = mktime(23,59,59,date("m"),date("t"),date("Y"));
				break;
			case 4:
				$begin = mktime(0, 0 , 0,date("m")-1,1,date("Y"));
				$end = mktime(23,59,59,date("m") ,0,date("Y"));
				break;
			default:
				$begin = strtotime(date("Y-m-d 00:00:00",time()));
				$end = strtotime(date("Y-m-d 23:59:59",time()));

		}
		//0全部；1公司入款,2线下入款,3人工入款,4活动优惠,5投注撤单,6提款退还,7代理返佣，8中奖派送，9提现记录，10投注记录，11现金交易
		$type = input('type',0);
		$list = [];
		switch( intval($type)){
			case 1:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("1 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 2:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>2,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("2 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>2,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 3:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>3,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("3 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>3,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 4:
				$total = Db::name("caijin_list")->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end])->count();
				$list = Db::name("caijin_list")->field("4 as label,cjje as je,cjhje as hje,fstime as time")->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end])->order("fstime DESC")->page($page,$limit)->select();
				break;
			case 5:
				$total = Db::name('touzhu_list_cd')->where(['username'=>$name])->whereTime("tz_time",'between',[$begin,$end])->count();
				$list = Db::name('touzhu_list_cd')->field("5 as label,tzje as je,tzhje as hje,rktime as time")->where(['username'=>$name])->whereTime("rktime",'between',[$begin,$end])->order("rktime DESC")->page($page,$limit)->select();
				break;
			case 7:
				$total = Db::name("day_agent")->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end])->count();
				$list = Db::name("day_agent")->field("7 as label,balance as je,fyqje as hje,add_time as time")->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end])->order("add_time DESC")->page($page,$limit)->select();
				break;
			case 9:
				$total = Db::name("tixian_list")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->count();
				$list = Db::name("tixian_list")->field("9 as label,txje as je,txhje as hje,txtime as time")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->order("txtime DESC")->page($page,$limit)->select();
				break;
			case 6:
				$total = Db::name("tixian_list_no")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->count();
				$list = Db::name("tixian_list_no")->field("6 as label,txje as je,0 as hje,txtime as time")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->order("txtime DESC")->page($page,$limit)->select();
				break;
			case 8:
				$total = Db::name("touzhu_list_pc")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->count();
				$list = Db::name("touzhu_list_pc")->field("8 as label,zjje as je,tzhje as hje,tz_time as time")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->order("tz_time DESC")->page($page,$limit)->select();
				break;
			case 10:
				$total = Db::name("touzhu_list_ok")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->count();
				$list = Db::name("touzhu_list_ok")->field("10 as label,tzje as je,tzhje as hje,tz_time as time")->where(['username'=>$name,'ifqs'=>1])->whereTime("tz_time",'between',[$begin,$end])->order("tz_time DESC")->page($page,$limit)->select();
				break;
			default:

				$list = Db::field("id,czclass as label,je,czhje as hje,cztime as time")->table("kkty_chongzhi_list")->where(['zt'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])
						->union(function($query) use($name,$begin,$end){
							$query->field('id,4 as label,cjje as je,cjhje as hje,fstime as time')->table('kkty_caijin_list')->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,5 as label,tzje as je,tzhje as hje,rktime as time')->table('kkty_touzhu_list_cd')->where(['username'=>$name])->whereTime("rktime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,7 as label,balance as je,fyqje as hje,add_time as time')->table('kkty_day_agent')->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,6 as label,txje as je,txhje as hje,txtime as time')->table('kkty_tixian_list')->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,6 as label,txje as je,0 as hje,txtime as time')->table('kkty_tixian_list_no')->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,8 as label,zjje as je,tzhje as hje,tz_time as time')->table('kkty_touzhu_list_pc')->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,10 as label,tzje as je,tzhje as hje,tz_time as time')->table('kkty_touzhu_list_ok')->where(['username'=>$name,'ifqs'=>1])->whereTime("tz_time",'between',[$begin,$end]);
						})->select();
				$total = count($list);
				array_multisort(array_column($list,'time'),SORT_DESC,array_column($list,'id'),SORT_DESC,$list);
				$list = array_slice($list,($page-1)*$limit,$limit);
		}
		$this->assign('title','账户明细');
		$this->assign('list',$list);
		$this->assign('page',$page);
		$this->assign('total',$total);
		$this->assign('date',$date);
		$this->assign('type',$type);
		$this->assign('total_page',ceil($total/$limit));
		return $this->fetch();
	}
	
	
	
	
	public function degree(){
//		if(!$this->user_all['username']) {
//			js_tishi('请先登录账号！','/mobile/user/login');exit;
//		}
		$usclass = Db::name('us_class')->order("czl asc")->select();
		foreach ($usclass as &$item){
			$item['dividend'] = floor($item['dividend']);
			$item['mearmoney'] = floor($item['mearmoney']);
			$item['czl'] = floor($item['czl']);
			$item['xml'] = floor($item['xml']);
			$item['zxtzxd'] = floor($item['zxtzxd']);
		}
		$this->assign('usclass',$usclass);
		$this->assign('title','等级说明');
		
		return $this->fetch();
	}

	public function rechargeMethod(){
		
		$this->assign('title','充值中心');
		if(!$this->user_all['username']) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$list = Db::name("pay_method")->where(['status'=>1])->order("seq asc")->select();
		$this->assign('list',$list);
		return $this->fetch("recharge_method");
	}
	public function rechargeList(){
		$type = input('type',0);
		$name =$this->user_all['username'];
		if( empty($name)) {
			js_tishi('请先登录账号！','/mobile/user/login');exit;
		}
		$type = intval($type);
		$method = Db::name('pay_method')->find($type);
		if( empty($method) || 0==intval($method['status'])) {
			js_tishi('请选中正确支付方案！','/mobile/member/rechargeMethod');exit;
		}
		$level = $this->user_all['us_class'];
		//线上第三方
		$onBand = Db::name('pay_type_list')->alias("a")
				->join("__PAY_XIANSHANG__ b",'a.method=b.id','LEFT')
				->where(['a.method_id'=>$type,'a.mob'=>1,'b.open'=>1])
				->field("a.id,b.pay_name,a.type_name,a.type_value ,b.level,1 as method, 0 as controller")
				->order('a.order','DESC')
				->select();

		foreach( $onBand as $k=>$v ){
			$levelAttr = explode(',',$v['level']);
			$onBand[$k]['controller'] = ChineseToPY($v['pay_name']);
			unset($onBand[$k]['level']);
			if( !in_array($level,$levelAttr) ) unset($onBand[$k]);
		}
		//线上支付宝或微信
		$onThird = Db::name("pay_xianshang")->where(['open'=>1,'is_code'=>1])->field("id,pay_name,level,0 as type_value,2 as method,0 as controller")->order('order','DESC')->select();
		$hasUser = Db::name("code_account")->where(['method_id'=>$type])->group("type")->column("type,count(*) as num");
		foreach( $onThird as $k=>$v ){
			$user_key = $v['pay_name']=="微信扫码" ? "wechat" : 'alipay';
			if( !isset($hasUser[$user_key]) && empty($hasUser[$user_key]) ){
				unset($onThird[$k]);
				continue;
			}
			$levelAttr = explode(',',$v['level']);
			unset($onThird[$k]['level']);
			if( !in_array($level,$levelAttr) ){
				unset($onThird[$k]);
				continue;
			}

		}

		//线下支付
		$offThird = Db::name("pay_xxlist")->where(['method_id'=>$type,'status'=>1])->field("id,xx_name as type_name,0 as type_value,xx_weixin,xx_zhifubao,xx_qq,xx_wangyin,3 as method,0 as controller")->select();
		foreach($offThird as &$v){
			if( 1==intval($v['xx_weixin']) ) $v['pay_name'] = '微信扫码';
			if( 1==intval($v['xx_zhifubao']) ) $v['pay_name'] = '支付宝扫码';
			if( 1==intval($v['xx_wangyin']) ) $v['pay_name'] = '银联转账';
			if( 1==intval($v['xx_qq']) ) $v['pay_name'] = 'QQ扫码';
			unset($v['xx_weixin']);
			unset($v['xx_zhifubao']);
			unset($v['xx_wangyin']);
			unset($v['xx_qq']);
		}
		unset($v);
		$list = array_merge($onBand,$onThird,$offThird);
		$money = Db::name('username')->where('username',$name)->value('je');
		$this->assign('title',$method['name']);
		$this->assign('money',$money);
		$this->assign('name',$name);
		$this->assign('list',$list);
		return $this->fetch("recharge_list");
	}

	public function getOfflineMessage(){
		$id = input('post.id',0);
		if( empty($id) ){
			return json_encode(['status'=>0,'msg'=>'支付方案错误，请重新选择']);
		}
		$info = Db::name("pay_xxlist")->find($id);
		return json_encode(['status'=>1,'data'=>$info]);
	}
	public function offLineRecharge(){

		$user = $this->user_all;
		if( !$user ) {
			return json_encode(['status'=>0,'msg'=>'请重新登录']);
		}
		//开始处理充值
		if( intval($user['swzh']) == 1) {
			return json_encode(['status'=>0,'msg'=>'试玩账号无法充值']);
		}
		$type = input('post.type',0);  //1:微信；2：支付宝：3：银行:4:QQ
		if( empty($type) ){
			return json_encode(['status'=>0,'msg'=>'支付方案错误，请重新选择']);
		}
		$money  = floatval(input('post.money',0));
		if( $money < 10 ){
			return json_encode(['status'=>0,'msg'=>'请输入正确金额']);
		}

		//内部账户
		if( intval($user['nbzh']) > 0 ){
			$state = new StateChange();
			$where = array('username'=>$user['username'],'nbzh'=>1);
			$state->SaveRecharge('username', $where, array('je'=>floatval($user['je'])+$money,'czzje'=>floatval($user['czzje'])+$money));
			return json_encode(['status'=>1]);
		}else{
			//判断防骚扰
			$count_sheuid = Db::name('xt_czfsr')->find();
			if($count_sheuid['open'] > 0) {
				$nowys = time() - $count_sheuid['time_xx'] * 60;
				$old_czjl = Db::name('chongzhi_list')->where('username',$user['username'])->where('cztime','>',$nowys)->find();
				if( !empty($old_czjl) ) {
					return json_encode(['status'=>0,'msg'=>"系统充值防骚扰已开启，{$count_sheuid['time_xx']}分钟内只能充值1次！"]);
				}
			}

			//会员等级与百分比
			$ts = Db::name('us_class')->where('id',$user['us_class'])->find();
			$usclass = '';
			$hyzsbs = 0;
			if( !empty($ts) ){
				$usclass = $ts['id'];
				$hyzsbs = $ts['czzsbl'];
			}
			//判断单次充值是否满一定金额，达到赠送金额；
			$xtcz = Db::name('xt_chongzhi')->where('id',1)->find();
			$xxczje = 0;
			$xxczzsbs = 0;
			if( !empty($xtcz) ){
				$xxczje = $xtcz['xxcz_je'];
				$xxczzsbs = $xtcz['xxcz_zs'];;
			}
			$liuyan = input('post.remark','');
			if( empty($liuyan) ){
				return json_encode(['status'=>0,'msg'=>'请输入验证信息']);
			}
			$enter_time = input('post.time','');
			if( empty($enter_time) ){
				return json_encode(['status'=>0,'msg'=>'请选择存入时间']);
			}
			//提交充值
			$time = strtotime($enter_time);
			$ddbh = 'S_'.$time.rand(0,999);
			$account_id = input('post.account',0);
			if( empty($account_id) ) {
				return json_encode(['status'=>0,'msg'=>'请选择充值账户！']);
			}
			$account = Db::name('pay_xxlist')->field("xx_bankren,method_id")->where('id',$account_id)->find();
			$method = Db::name('pay_method')->find($account['method_id']);

			$method_money = 0.00;
			if( floatval( $method['money'] ) > 0 ){
				if( 0==intval( $method['method'] ) ){
					//金额
					$method_money = $method['money'];
				}else{
					//比例
					$method_money = floatval($money) * floatval($method['money']) / 100;
				}
			}
			$method_money = sprintf("%.2f",substr(sprintf("%.3f", $method_money), 0, -2));
			$xxbank='';
			switch( intval($type) ){
				case 1:
					$xxbank='微信转账';
					break;
				case 2:
					$xxbank='支付宝转账';
					break;
				case 3:
					$xxbank='网银转账';
					break;
				case 4:
					$xxbank='QQ转账';
					break;
			}
			$czadmin='';
			$czclass=2;
			$msje=0;$msbs=0;

			if($money>=$xxczje){
				$msje = $money*$xxczzsbs/100;
				$msbs = $xxczzsbs;
			}

			$zsbs = $hyzsbs;
			$zsje = $money*$hyzsbs/100;
			$chongzhi = new ChongZhi();

			if($chongzhi->WeiXinRecharge($czadmin,$ddbh,$money,$user['username'],'0','0',$czclass,$xxbank,$time,get_ip(),'0',$liuyan,$zsje,$zsbs,$msje,$msbs,$usclass,$account['xx_bankren'],$method_money,$user['je'])){
				return json_encode(['status'=>1]);
			}else{
				return json_encode(['status'=>0,'msg'=>'充值失败！']);
			}
		}
	}
}